package cn.hxzy.kaoshi.mapper;

import cn.hxzy.kaoshi.entity.SysExamError;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public interface SysExamErrorMapper extends BaseMapper<SysExamError> {
    @Insert("   INSERT INTO sys_exam_error (user_id, subject_id, ordinal_number)\n" +
            "    VALUES (#{userId}, #{subjectId}, 1)\n" +
            "    ON DUPLICATE KEY UPDATE ordinal_number = ordinal_number + 1")
    void insertOrUpdate(SysExamError sysExamError);

    @Select("SELECT * FROM `sys_exam_error` WHERE user_id=#{userId}")
    List<SysExamError> findAllByUserId(Long userId);

@Select("SELECT\n" +
        "\tsys_subject_label.label_name, \n" +
        "\tsys_subject.subject_label,sys_subject.subject_name,subject_type,sys_subject.subject_id,sys_exam_error.ordinal_number \n" +
        "FROM\n" +
        "\tsys_exam_error\n" +
        "\tINNER JOIN\n" +
        "\tsys_subject\n" +
        "\tON \n" +
        "\t\tsys_exam_error.subject_id = sys_subject.subject_id,\n" +
        "\t sys_subject_label" +
        " WHERE\n" +
        "\t sys_subject.subject_label=sys_subject_label.label_id and  sys_subject.subject_id = #{subjectId}")
     Map findErrorSubjcet(Integer subjectId);

}
